home *** CD-ROM | disk | FTP | other *** search
/ Champak 99 / (Vol 99) Jan 19 2010.iso / Games / balls.swf / scripts / frame_3 / DoAction.as < prev   
Encoding:
Text File  |  2010-01-19  |  2.2 KB  |  60 lines

  1. n = 10;
  2. riseNow = false;
  3. fallNow = false;
  4. Stage.scaleMode = "noScale";
  5. this.onEnterFrame = function()
  6. {
  7.    i = 1;
  8.    while(i < n)
  9.    {
  10.       j = 1;
  11.       while(j < n)
  12.       {
  13.          if(i != j && _root["ball" + i].inside != false && _root["ball" + j].inside != false)
  14.          {
  15.             distx = _root["ball" + j]._x - _root["ball" + i]._x;
  16.             disty = _root["ball" + j]._y - _root["ball" + i]._y;
  17.             dist = Math.sqrt(distx * distx + disty * disty);
  18.             if(dist <= 30)
  19.             {
  20.                theta = Math.atan2(disty,distx);
  21.                nx = Math.cos(theta);
  22.                ny = Math.sin(theta);
  23.                x = _root["ball" + i].dx - _root["ball" + j].dx;
  24.                y = _root["ball" + i].dy - _root["ball" + j].dy;
  25.                ndot = x * nx + y * ny;
  26.                ix = nx * ndot;
  27.                iy = ny * ndot;
  28.                distx2 = - _root["ball" + j]._x + _root["ball" + i]._x;
  29.                disty2 = - _root["ball" + j]._y + _root["ball" + i]._y;
  30.                dist2 = distx * distx + disty * disty;
  31.                theta2 = Math.atan2(disty2,distx2);
  32.                nx2 = Math.cos(theta2);
  33.                ny2 = Math.sin(theta2);
  34.                x2 = - _root["ball" + i].dx + _root["ball" + j].dx;
  35.                y2 = - _root["ball" + i].dy + _root["ball" + j].dy;
  36.                ndot2 = x2 * nx2 + y2 * ny2;
  37.                ix2 = nx2 * ndot2;
  38.                iy2 = ny2 * ndot2;
  39.                _root["ball" + i].dx -= ix;
  40.                _root["ball" + i].dy -= iy;
  41.                _root["ball" + i]._x += _root["ball" + i].dx;
  42.                _root["ball" + i]._y += _root["ball" + i].dy;
  43.                movex = Math.cos(theta) * (30 - dist) / 2;
  44.                movey = Math.sin(theta) * (30 - dist) / 2;
  45.                _root["ball" + i]._x -= movex;
  46.                _root["ball" + i]._y -= movey;
  47.                _root["ball" + j]._x += movex;
  48.                _root["ball" + j]._y += movey;
  49.                _root["ball" + j].dx -= ix2;
  50.                _root["ball" + j].dy -= iy2;
  51.                _root["ball" + j]._x += _root["ball" + j].dx;
  52.                _root["ball" + j]._y += _root["ball" + j].dy;
  53.             }
  54.          }
  55.          j++;
  56.       }
  57.       i++;
  58.    }
  59. };
  60.